package common;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import com.igexin.sdk.PushManager;
import com.laoxinwen.app.R;
import com.umeng.analytics.MobclickAgent;

import java.util.List;

import util.ToastUtil;
import util.bitmap.FileUtil;

public class MyApp extends Application {
    private static MyTheme myTheme;
    private static MyApp app;

    public static void switchTheme(int themeId) {
        MyTheme myTheme = MyTheme.getTheme(themeId);
        if (myTheme != null) {
            app.setTheme(myTheme.getThemeResId());
            MyApp.myTheme = myTheme;
        }
    }

    public static MyTheme getMyTheme() {
        return myTheme;
    }

    public static Context getContext() {
        return app.getApplicationContext();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        UserConfig.init(this);
        FileUtil.init(this);
        ToastUtil.init(this);
        MyTheme.init();
        MyApp.app = this;
        //检查推送等、夜间模式以及字体大小
        MobclickAgent.openActivityDurationTrack(false);
        PushManager.getInstance().initialize(app);
        if (!UserConfig.isPushOn()) {
            PushManager.getInstance().turnOffPush(app);
        }
        int themeId = UserConfig.getMainTheme();
        if (UserConfig.isNightMode()) {
            themeId = MyTheme.THEME_NIGHT;
        }
        MyApp.switchTheme(themeId);
    }


}
